package leetcode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0560.java
 * @Author : WangRuoyu
 * @Date 2023/9/5 15:55
 */


public class Q0560 {
    public int subarraySum(int[] nums, int k) {
        int[] a = new int[nums.length + 1];
        int res = 0;
        for (int i = 1; i < a.length; i++) {
            a[i] = a[i - 1] + nums[i - 1];
        }
        for (int i = 0; i < nums.length; i++) {
            for (int j = i; j < nums.length; j++) {
                if (a[j + 1] - a[i] == k) res++;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Q0560 sl = new Q0560();
        int[] nums = {-1, -1, 1};
        int k = 0;
        System.out.println(sl.subarraySum(nums, k));
    }
}